package edu.gdkm.dao;

import edu.gdkm.pojo.Skill;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SkillDao {

    // 根据ID查询
    @Select("SELECT * FROM Skills WHERE skill_id = #{skillId}")
    Skill selectById(Integer skillId);

    // 根据简历ID查询
    @Select("SELECT * FROM Skills WHERE resume_id = #{resumeId}")
    List<Skill> selectByResumeId(Integer resumeId);
    
    // 根据简历ID和分类查询
    @Select("SELECT * FROM Skills WHERE resume_id = #{resumeId} AND category = #{category}")
    List<Skill> selectByResumeIdAndCategory(@Param("resumeId") Integer resumeId, @Param("category") String category);

    // 查询所有
    @Select("SELECT * FROM Skills")
    List<Skill> selectAll();

    // 新增
    @Insert("INSERT INTO Skills(resume_id, name, proficiency, category) " +
            "VALUES(#{resumeId}, #{name}, #{proficiency}, #{category})")
    @Options(useGeneratedKeys = true, keyProperty = "skillId")
    int insert(Skill skill);

    // 更新
    @Update("UPDATE Skills SET resume_id = #{resumeId}, name = #{name}, proficiency = #{proficiency}, " +
            "category = #{category} WHERE skill_id = #{skillId}")
    int update(Skill skill);

    // 删除
    @Delete("DELETE FROM Skills WHERE skill_id = #{skillId}")
    int delete(Integer skillId);
    
    // 根据简历ID删除
    @Delete("DELETE FROM Skills WHERE resume_id = #{resumeId}")
    int deleteByResumeId(Integer resumeId);
}
    